package com.tj.jinzao.presenter;


import android.database.Cursor;

import com.tj.jinzao.base.BasePresenter;
import com.tj.jinzao.base.IBaseView;
import com.tj.jinzao.model.City;
import com.tj.jinzao.provider.ProviderContract;

import java.util.ArrayList;
import java.util.List;

/**
 * 地址处理
 * Created by wjy 2018/12/10.
 */
public class CityPresenter extends BasePresenter<IBaseView<List<City>>> {

    public CityPresenter(IBaseView<List<City>> view) {
        super(view);
    }

    public List<String> getCityList() {
        Cursor cursor = null;
        try {
            cursor = mView.getContext().getContentResolver().query(ProviderContract.City.CONTENT_URI
                    , new String[]{ProviderContract.City.FATHER_NAME}, "0=0 group by " + ProviderContract.City.FATHER_NAME, null
                    , ProviderContract.City.CITY_CODE + " ASC");
            if (cursor != null && cursor.getCount() > 0) {
                List<String> list = new ArrayList();
                cursor.moveToFirst();
                do {
                    list.add(cursor.getString(0));
                } while (cursor.moveToNext());
                return list;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}